<#assign className = table.className>
<#assign classNameLower = className?uncap_first>
package ${basepackage}.service.impl;

import ${prefixpackage}.model.paging.PagingResult;
import ${prefixpackage}.service.impl.${prefix}BaseServiceImpl;
import ${mapperPackage}.${className}Mapper;
import ${modelPackage}.${className};
import ${modelPackage}.${className}Criteria;
import ${basepackage}.service.I${className}Service;

import ${prefixpackage}.constants.ConstConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * ${className}的 DB操作service
 *
 * @author jdd
 * @version 1.0
 * @date <#if now??>${now?string('yyyy-MM-dd HH:mm:ss')}</#if>
 */
@Service
@Transactional(rollbackFor={Exception.class})
public class ${className}ServiceImpl extends ${prefix}BaseServiceImpl<${className}, ${className}Criteria, ${table.idColumn.javaType}> implements I${className}Service {

	private static Logger logger = LoggerFactory.getLogger(${className}ServiceImpl.class);

	@Resource
	@SuppressWarnings("SpringJavaAutowiringInspection")
	private ${className}Mapper ${classNameLower}Mapper;

	@Override
	public List<${className}> queryAll(String orderByClause) {
		logger.debug("[${className}ServiceImpl][queryAll]entering, orderByClause:{}", orderByClause);
		${className}Criteria criteria = new ${className}Criteria();
		criteria.createCriteria();
		criteria.setOrderByClause(orderByClause);
		return queryByCriteria(criteria);
	}

	@Override
	public List<${className}> fallloadByCriteria(int pageSize, ${className}Criteria criteria) {
		logger.debug("[${className}ServiceImpl][fallloadByCriteria]entering, pageSize:{}", pageSize);
		return null;
	}

	@Override
	public PagingResult<${className}> pagingByCriteria(int pageNo, int pageSize, ${className}Criteria criteria, ${className} ${classNameLower}) {
		logger.debug("[${className}ServiceImpl][pagingByCriteria] entering, pageNo:{},pageSize:{}", pageNo, pageSize);
		// 确保pageNo合法
		pageNo = pageNo <= 0 ? 1 : pageNo;
		pageSize = pageSize <= 0 ? ConstConfig.PAGE_SIZE_DEFAULT : pageSize;
		// 确保pageSize合法
		int offset = (pageNo - 1) * pageSize;

		// 构造查询条件
		if (criteria == null) {
			criteria = new ${className}Criteria();
		}

		criteria.setLimitOffset(offset);
		criteria.setLimitRows(pageSize);
		logger.info("[${className}ServiceImpl][pagingByCriteria] offset:{}, pageNo: {},pageSize:{}", offset, pageNo, pageSize);
		int count = super.countByCriteria(criteria);
		List<${className}> dataList = ${classNameLower}Mapper.selectByExample(criteria);
		// 返回分页数据
		logger.info("[${className}ServiceImpl][pagingByCriteria] result, pageNo: {},pageSize:{},count:{},dataListSize:{}",
				pageNo, pageSize, count, dataList != null ? dataList.size() : 0);
		return new PagingResult<>(pageNo, pageSize, count, dataList);
	}

	@Override
	public ${className}Mapper getBaseMapper() {
			return ${classNameLower}Mapper;
	}
}